package com.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bean.wd_order;
import com.service.OrderService;

@Controller
@RequestMapping("/order")
public class OrderAction {
	
	@InitBinder  
	public void initBinder(WebDataBinder binder) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");  
	dateFormat.setLenient(false);  
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); 
	}
	
	@Autowired
	private OrderService service;
	
	@RequestMapping("/orderUpdate.do")
	public String orderUpdate(String id,Model model){
		System.out.println(id);
		wd_order order = service.selectById(id);
		System.out.println(order.getPayTypeName());
		model.addAttribute("order", order);
		return "orderUpdate";
	}
	@RequestMapping("/orderUpdate1.do")
	public String orderUpdate1(wd_order order){
		System.out.println(order.getName());
		service.update(order);
		
		return "redirect:selectAll.do";
	}
	
	@RequestMapping("/orderAdd1.do")
	public String orderAdd1(wd_order order){
	
		System.out.println("orderAdd1order"+order.getCreateTime());
		service.insert(order);
		return "redirect:selectAll.do";
	}
	@RequestMapping("/selectAll.do")
	public String selectAll(Model model){
		List<wd_order> list = service.selectAll();
		System.out.println(list.get(1).getCustomerName());
		model.addAttribute("listOrder",list);
		return "orderManager";
	}
	
	@RequestMapping("/orderDelete.do")
	public String orderDelete(String id){
		System.out.println("orderDelete");
		service.delete(id);
		return "redirect:selectAll.do";
	}
}
